Ext.onReady(function () {
    Ext.QuickTips.init();
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
    var columns = [
        { id: 'name', header: 'Name', dataIndex: 'name__c', width: 200 },
        { header: 'Status', dataIndex: 'status', type: 'combo' },
        { header: 'Point', dataIndex: 'point', width: 50 },
        { header: 'Hour', dataIndex: 'hour', width: 50 },
        { header: 'Assignee', dataIndex: 'assignee', type: 'combo' },
        { header: 'Team', dataIndex: 'team__c', type: 'combo' },
        { header: 'Description', dataIndex: 'desc', width: 300 }
    ];
    var recordType = [
        { name: 'id__c', mapping: 'id__c' },
        { name: 'name__c', mapping: 'name__c' },
        { name: 'status', mapping: 'status.value', type: 'string' },
        { name: 'point', mapping: 'point', type: 'int' },
        { name: 'hour', mapping: 'hour', type: 'int' },
        { name: 'assignee', mapping: 'assignee.display', type: 'string' },
        { name: 'team__c', mapping: 'team__c.display', type: 'string' },
        { name: 'sprint__c', mapping: 'sprint__c', type: 'string' },
        { name: 'desc', mapping: 'desc', type: 'string' },
        { name: 'objecttype', mapping: 'objecttype', type: 'string' }
    ];
    var formConfig = { title: 'New Backlog',
        items: [{ fieldLabel: 'First Name', name: 'first', allowBlank: false },
            { fieldLabel: 'Last Name', name: 'last' },
            { fieldLabel: 'Company', name: 'company' },
            { fieldLabel: 'Email', name: 'email', vtype: 'email' },
            new Ext.form.TimeField({ fieldLabel: 'Time', name: 'time', minValue: '8:00am', maxValue: '6:00pm' })
        ]
    };
    var expander = new Ext.ux.grid.RowExpander({
        tpl: new Ext.Template(
            '<p><b>Name:</b> {name}</p><br>',
            '<p><b>Description:</b> {desc}</p>'
        )
    });
    var gridPanel = new ScrumEditorGridPanel({ id: 'grid-panel',
        storeConfig: { proxyConfig: { url: 'SprintDetail.aspx' }, readerConfig: {recordType: recordType} },
        cmConfig: { columns: columns },
        newPwConfig: { formConfig: formConfig },
        sm: new Ext.grid.RowSelectionModel({
            singleSelect: true,
            listeners: {
                selectionchange: function (sel) {
                    var rec = sel.getSelected();
                    if (rec) {
                        Ext.getCmp('east-panel').body.update('<b><u>' + 'Name:' + rec.get('name') + '</u></b><br>' + 'Description:' + rec.get('desc'));
                    }
                }
            }
        }),
        plugins: expander,
        viewConfig: {
            forceFit: true,
            enableRowBody: true,
            showPreview: true,
            getRowClass: function (record, rowIndex, p, ds) {
                if (this.showPreview) {
                    p.body = '<p>' + record.data.excerpt + '</p>';
                    return 'x-grid3-row-expanded';
                }
                return 'x-grid3-row-collapsed';
            }
        }
    });
    var viewport = new DefaultScrumViewport({
        center: { title: 'Backlog List', gridPanel: gridPanel }
    });
});
